use APSR_final_dataset.dta, clear


*****************************************
 *******GINI Occup * PSLAVE on Tax Diff*****
 

reg tax_diff county_sei_gini_whitemale pslave ineq_int std_area std_log_pop std_fbprop1860 std_farmval river rail1860 stateid_* if confederate==1


generate MV=((_n-1)/100)
replace  MV=. if _n>100

*     ****************************************************************  *
*       Grab elements of the coefficient and variance-covariance matrix *
*       that are required to calculate the marginal effect and standard *
*       errors.                                                         *
*     ****************************************************************  *

matrix b=e(b) 
matrix V=e(V)
 
scalar b1=b[1,1] 
scalar b2=b[1,2]
scalar b3=b[1,3]


scalar varb1=V[1,1] 
scalar varb2=V[2,2] 
scalar varb3=V[3,3]

scalar covb1b3=V[1,3] 
scalar covb2b3=V[2,3]

scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3

*     ****************************************************************  *
*       Calculate the marginal effect of X on Y for all MV values of    *
*       the modifying variable Z.                                       *
*     ****************************************************************  *

gen conb=b1+b3*MV if _n<150


*     ****************************************************************  *
*       Calculate the standard errors for the marginal effect of X on Y *
*       for all MV values of the modifying variable Z.                  *
*     ****************************************************************  *

gen conse=sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV) if _n<150 


*     ****************************************************************  *
*       Generate upper and lower bounds of the confidence interval.     *
*       Specify the significance of the confidence interval.            *
*     ****************************************************************  *

gen a=1.96*conse
 
gen upper=conb+a
 
gen lower=conb-a

*     ****************************************************************  *
*       Graph the marginal effect of X on Y across the desired range of *
*       the modifying variable Z.  Show the confidence interval.        *
*     ****************************************************************  *

label var MV "Proportion Enslaved"

graph twoway (line conb MV, title("Per Capita Change in Tax 1880-1870") ytitle("Marginal effect of Intra-White Occ. Inequality") ///
color(black)graphregion(fcolor(white) ifcolor(white)) legend(off) ///
clwidth(medium) clcolor(blue)clcolor(black)) ///
(line upper MV, clpattern(dash) clwidth(thin) clcolor(black)) ///
 (line lower MV, clpattern(dash) clwidth(thin) clcolor(black))
 
 graph export interaction_occgini_tax_diff.pdf, replace 


*****************************************
 *******GINI Occup * PSLAVE on Whipple80*****
 use APSR_final_dataset.dta, clear

reg whipple80_white county_sei_gini_whitemale pslave ineq_int  std_area std_log_pop std_fbprop1860 std_farmval river rail1860 std_whipple50_white stateid_* if confederate==1


generate MV=((_n-1)/100)
replace  MV=. if _n>100

*     ****************************************************************  *
*       Grab elements of the coefficient and variance-covariance matrix *
*       that are required to calculate the marginal effect and standard *
*       errors.                                                         *
*     ****************************************************************  *

matrix b=e(b) 
matrix V=e(V)
 
scalar b1=b[1,1] 
scalar b2=b[1,2]
scalar b3=b[1,3]


scalar varb1=V[1,1] 
scalar varb2=V[2,2] 
scalar varb3=V[3,3]

scalar covb1b3=V[1,3] 
scalar covb2b3=V[2,3]

scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3

*     ****************************************************************  *
*       Calculate the marginal effect of X on Y for all MV values of    *
*       the modifying variable Z.                                       *
*     ****************************************************************  *

gen conb=b1+b3*MV if _n<150


*     ****************************************************************  *
*       Calculate the standard errors for the marginal effect of X on Y *
*       for all MV values of the modifying variable Z.                  *
*     ****************************************************************  *

gen conse=sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV) if _n<150 


*     ****************************************************************  *
*       Generate upper and lower bounds of the confidence interval.     *
*       Specify the significance of the confidence interval.            *
*     ****************************************************************  *

gen a=1.96*conse
 
gen upper=conb+a
 
gen lower=conb-a

*     ****************************************************************  *
*       Graph the marginal effect of X on Y across the desired range of *
*       the modifying variable Z.  Show the confidence interval.        *
*     ****************************************************************  *

label var MV "Proportion Enslaved"

graph twoway (line conb MV, title("Age Heaping 1880") ytitle("Marginal effect of Intra-White Occ. Inequality") ///
color(black)graphregion(fcolor(white) ifcolor(white)) legend(off) ///
clwidth(medium) clcolor(blue)clcolor(black)) ///
(line upper MV, clpattern(dash) clwidth(thin) clcolor(black)) ///
 (line lower MV, clpattern(dash) clwidth(thin) clcolor(black))
 
 graph export interaction_occgini_whipple80.pdf, replace 


********************************************
******Occ Ineqq * PSLAVE on GOVT EMPLOY*****
 use APSR_final_dataset.dta, clear
 
reg lg_govt_employ_pc80 county_sei_gini_whitemale pslave  ineq_int std_area std_log_pop std_fbprop1860 std_farmval  river rail1860 std_govt_employ_pc50 stateid_* if confederate==1



generate MV=((_n-1)/100)
replace  MV=. if _n>100

*     ****************************************************************  *
*       Grab elements of the coefficient and variance-covariance matrix *
*       that are required to calculate the marginal effect and standard *
*       errors.                                                         *
*     ****************************************************************  *

matrix b=e(b) 
matrix V=e(V)
 
scalar b1=b[1,1] 
scalar b2=b[1,2]
scalar b3=b[1,3]


scalar varb1=V[1,1] 
scalar varb2=V[2,2] 
scalar varb3=V[3,3]

scalar covb1b3=V[1,3] 
scalar covb2b3=V[2,3]

scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3

*     ****************************************************************  *
*       Calculate the marginal effect of X on Y for all MV values of    *
*       the modifying variable Z.                                       *
*     ****************************************************************  *

gen conb=b1+b3*MV if _n<150


*     ****************************************************************  *
*       Calculate the standard errors for the marginal effect of X on Y *
*       for all MV values of the modifying variable Z.                  *
*     ****************************************************************  *

gen conse=sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV) if _n<150 


*     ****************************************************************  *
*       Generate upper and lower bounds of the confidence interval.     *
*       Specify the significance of the confidence interval.            *
*     ****************************************************************  *

gen a=1.96*conse
 
gen upper=conb+a
 
gen lower=conb-a

*     ****************************************************************  *
*       Graph the marginal effect of X on Y across the desired range of *
*       the modifying variable Z.  Show the confidence interval.        *
*     ****************************************************************  *

label var MV "Proportion Enslaved"

graph twoway (line conb MV, title("Government Employment in 1880") ytitle("Marginal effect of Intra-White Occ. Inequality") ///
color(black)graphregion(fcolor(white) ifcolor(white)) legend(off) ///
clwidth(medium) clcolor(blue)clcolor(black)) ///
(line upper MV, clpattern(dash) clwidth(thin) clcolor(black)) ///
 (line lower MV, clpattern(dash) clwidth(thin) clcolor(black))
 
 graph export interaction_occgini_govtemploy.pdf, replace 
